import java.io.*;
import java.util.*;

public class h_10 {
    public static void main(String[] args) throws IOException {
        File f=new File("peopleName.txt");
        //获取10个女生和男生的文件
        if(!f.exists()){
            ArrayList<String> nameFile = getNameFile("names.txt");
            System.out.println(nameFile);
            BufferedWriter fw=new BufferedWriter(new FileWriter("peopleName.txt"));
            BufferedWriter fw2=new BufferedWriter(new FileWriter("peopleName2.txt"));
            for (String s:nameFile
                 ) {
                fw.write(s);
                fw.newLine();
                fw2.write(s);
                fw2.newLine();
            }
            fw.close();
            fw2.close();
        }
        //从peopleName.txt文件中获取一个男女生的list
        BufferedReader fr=new BufferedReader(new FileReader(f));
        String str=null;
        ArrayList<String> list=new ArrayList<>();
        while((str=fr.readLine())!=null){
            list.add(str);
        }
        if(list.size()==0){
            BufferedWriter p=new BufferedWriter(new FileWriter("peopleName.txt"));
            BufferedReader r=new BufferedReader(new FileReader("peopleName2.txt"));
            String ss=null;
            while((ss=r.readLine())!=null){
                p.write(ss);
                p.newLine();
                list.add(ss);
            }
            p.close();
        }
        Collections.shuffle(list);
        System.out.println(list.get(0));
        list.remove(0);
        BufferedWriter fw=new BufferedWriter(new FileWriter("peopleName.txt"));
        for (String s:list
        ) {
            fw.write(s);
            fw.newLine();
        }
        fw.close();
    }
    public static ArrayList<String> getNameFile(String file) throws IOException {
        ArrayList<String> list=new ArrayList<>();
        BufferedReader fr=new BufferedReader(new FileReader(file));
        String str=null;
        while((str=fr.readLine())!=null){
            list.add(str);
        }
        HashSet<String> setMan=new HashSet<>();
        HashSet<String> setWoman=new HashSet<>();
        while(true){
            if(setMan.size()==10){
                break;
            }
            //随机
            Collections.shuffle(list);
            if(list.get(0).split("-")[1].equals("男")){
                setMan.add(list.get(0));
            }

        }
        while(true){
            if(setWoman.size()==10){
                break;
            }
            //随机
            Collections.shuffle(list);
            if(list.get(0).split("-")[1].equals("女")){
                setWoman.add(list.get(0));
            }

        }
        ArrayList<String> list2=new ArrayList<>();
        for (String s:setMan
             ) {
            list2.add(s);
        }
        for (String s:setWoman
             ) {
            list2.add(s);
        }
        return list2;
    }
    public static void getName(String file){

    }
}
